<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // join 数组转化为字符串   join 分隔符
        var arr = [1, 8, 7, 6];

        var arr1 = [3, 8, 9, 6, 7, 4]
        Array.prototype.join1 = function (a) {
            var str = '';
            a = a == undefined ? ',' : a // 三元表达式
            for (var i = 0; i < this.length; i++) { 
                if (i == this.length - 1) {
                    str += this[i] // str= str+this[i]
                } else {
                    str += this[i] + a;
                }
            }
            return str;
        }

        console.log(arr.join1('-'));
        console.log(arr1.join1('+')); // 添加分隔符



    </script>
</body>

</html>